home *** CD-ROM | disk | FTP | other *** search
- //: C06:Nojump.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Can't jump past constructors
-
- class X {
- public:
- X();
- };
-
- X::X() {}
-
- void f(int i) {
- if(i < 10) {
- //! goto jump1; // Error: goto bypasses init
- }
- X x1; // Constructor called here
- jump1:
- switch(i) {
- case 1 :
- X x2; // Constructor called here
- break;
- //! case 2 : // Error: case bypasses init
- X x3; // Constructor called here
- break;
- }
- }
-
- int main() {
- f(9);
- f(11);
- }///:~
-